package it.unibo.refolding.pico;

import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;

public class PlainDirectionData extends AbstractDirectionData {

	public final double velocity;
	
	public static final PlainDirectionData EMPTY = new PlainDirectionData(
	    ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.EMPTY_SHORT_ARRAY, 0);

	public PlainDirectionData(short[] deflection, short[] z, double velocity) {
		super(deflection, z);
		this.velocity = velocity;
	}

	@Override
	public List<Shape> draw(double svgDefScale) {
		List<Shape> result = new ArrayList<>();
		if (deflection.length != 0) {
			Point2D.Double start = new Point2D.Double(z(0), deflection[0] * svgDefScale);
			for (int i = 0; i < deflection.length - 1; ++i) {
				Point2D.Double end = new Point2D.Double(z(i + 1), deflection[i + 1] * svgDefScale);
				result.add(new Line2D.Double(start, end));
				start = end;
			}
		}
		return result;
	}

	@Override
	public PlainDirectionData subRange(int from, int to) {
		return new PlainDirectionData(
			Arrays.copyOfRange(deflection, from, to), Arrays.copyOfRange(z, from, to),
			velocity);
	}
	
	@Override
	public boolean equals(Object o) {
		if (!super.equals(o)) {
			return false;
		}
		PlainDirectionData other = (PlainDirectionData) o;
		return velocity == other.velocity;
	}
}
